package com.niiwoo.civet.trade.service.local.newRefund.notify.mq;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.niiwoo.asset.dto.mq.RepaymentResultDTO;
import com.niiwoo.civet.trade.dao.entity.RefundNotifyRecord;
import com.niiwoo.civet.trade.dao.mapper.RefundWithholdOrderMapperExt;
import com.niiwoo.civet.trade.service.local.newRefund.notify.dto.RefundNotifyDTO;
import com.niiwoo.civet.trade.service.local.newRefund.notify.enums.RefundNotifyEnum;
import com.niiwoo.civet.trade.service.local.newRefund.notify.enums.RefundNotifyRefundStatusEnum;

/**
 * 融360标的还款MQ通知
 * 
 * 触发条件：还款成功、失败
 * 
 * @author: kevin.jia
 * @version 1.0.0
 */
@Component
public class R360RefundResultNotify extends MQRefundNotify {
	
    @Autowired
    protected RefundWithholdOrderMapperExt refundWithholdOrderMapper;
	
	@Override
	public Object bulidParam(RefundNotifyDTO refundNotifyDTO) {
		RefundNotifyRecord refundNotifyRecord = refundNotifyDTO.getRefundNotifyRecord();
		
		RepaymentResultDTO repaymentResultDTO = new RepaymentResultDTO();
		repaymentResultDTO.setProjectId(refundNotifyDTO.getProjectId());
		repaymentResultDTO.setApplayOrderId(refundNotifyRecord.getOrgRequestNo());
		repaymentResultDTO.setPeriod(refundNotifyRecord.getCurrentPeriod());
		repaymentResultDTO.setErrorMessage(refundNotifyRecord.getRefundMessage());
		if (RefundNotifyRefundStatusEnum.REPAYMENT_FINISH.getStatus().equals(refundNotifyRecord.getRefundStatus())) {
			repaymentResultDTO.setRepaymentResult(true);
		} else if (RefundNotifyRefundStatusEnum.REPAPYMENT_FAIL.getStatus().equals(refundNotifyRecord.getRefundStatus())) {
			repaymentResultDTO.setRepaymentResult(false);
		} else {
			return null;
		}
		return repaymentResultDTO;
	}
	
	@Override
	public RefundNotifyEnum getType() {
		return RefundNotifyEnum.R360_REFUND_RESULT;
	}
}